﻿using HK.Core.GUIEx.Protocol.Attribute;
using HK.Core.Serializable.Protocol.Attribute;
using HK.Core.Utils;

namespace HK.Core.Serializable.Attribute
{
    /// <summary>
    /// 接口 : Attribute - ListView
    /// </summary>
    public class ListViewAttribute : SBodyAttribute, IListViewAttribute
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="iCaption">标题</param>
        /// <param name="iElementKey">ElementKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iPageSize">分页大小(即:每页的大小)</param>
        /// <param name="iPageable">可分页</param>
        /// <param name="iDrawFromUnity">Unity自身Draw绘制</param>
        public ListViewAttribute(string iCaption, string iElementKey, int iOptions = (int)GUIOperateOptions.DefaultListView, 
            int iPageSize = 30, bool iPageable = false, bool iDrawFromUnity = true) : base(iCaption, null, null, iOptions)
        {
            ElementKey = iElementKey;
            PageSize = iPageSize;
            Pageable = iPageable;
            DrawFromUnity = iDrawFromUnity;
        }
        
        /// <summary>
        /// 保护构造函数
        /// </summary>
        protected ListViewAttribute() : base() {}

        /// <summary>
        /// Element的Key Property
        /// </summary>
        public string ElementKey { get; private set; } = null;

#region Options

        /// <summary>
        /// 可排序
        /// </summary>
        public bool Sortable => UtilsBytes.CheckBytes(Options, (int)GUIOperateOptions.Sortable);
        
        
        private bool _pageable = false;
        /// <summary>
        /// 可分页
        /// </summary>
        public bool Pageable
        {
            get => _pageable || UtilsBytes.CheckBytes(Options, (int)GUIOperateOptions.Pageable);
            private set => _pageable = value;
        }

        #endregion

#region Pagination

        /// <summary>
        /// 分页大小
        /// <para>* 既每页的大小</para>
        /// </summary>
        public int PageSize { get; private set; } = 0;

#endregion

    }
}
